
/** $Id: MessageHandlerFactory.java 60 2009-06-15 08:47:09Z salbanese0080@gmail.com $ */

package org.aquiferserver.server.messaging;

import java.util.HashMap;
import java.util.Map;

import org.aquiferserver.common.AquiferMessage;
import org.aquiferserver.common.MessageType;

/**
 * @author Seth Albanese
 * @version $Id: MessageHandlerFactory.java 60 2009-06-15 08:47:09Z salbanese0080@gmail.com $
 */
public class MessageHandlerFactory {

	private Map<String, MessageHandler> handlers = new HashMap<String, MessageHandler>();
	
	public MessageHandler getMessageHandler( String clazz ) throws AquiferMessagingException
	{		
		if( handlers.containsKey( clazz ) )
		{
			return handlers.get( clazz );
		}
		else
		{
			throw new AquiferMessagingException( "Unknown message type " + clazz );
		}
	}
	
	public MessageHandler getMessageHandler( AquiferMessage msg ) throws AquiferMessagingException
	{
		String clazz = msg.getClass().getCanonicalName();
		return getMessageHandler( clazz );
	}
	
	public void setHandlers( Map<String, MessageHandler> handlers )
	{
		this.handlers = handlers;
	}
	
}
